#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    int fd = open("log.txt",O_CREAT | O_WRONLY | O_TRUNC, 0666);
    if(fd < 0) exit(1);
    
    dup2(fd, 1);
    
    printf("fd:%d\n", fd);
    printf("hello printf\n");
    fprintf(stdout, "hello fprintf\n");
    const char *msg = "hello world\n";
    write(fd, msg, strlen(msg));
    
    return 0;
}
